package com.wwt.server.controller;

import com.wwt.server.pojo.Admin;
import com.wwt.server.service.IAdminService;
import com.wwt.server.vo.Result;
import com.wwt.server.vo.params.AdminLoginParams;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.security.Principal;

@RestController
@Api(tags = "登录控制器")
public class LoginController {

    @Autowired
    private IAdminService adminService;

    @ApiOperation(value = "登陆之后返回Token")
    @PostMapping("/login")
    public Result login(@RequestBody AdminLoginParams params, HttpServletRequest request){
        return adminService.login(params.getUsername(),params.getPassword(),params.getCode(),request);
    }
    @GetMapping("/admin/info")
    @ApiOperation(value = "获取当前用户信息")
    public Admin getAdminInfo(Principal principal){
        return adminService.getAdminInfo(principal.getName());
    }

    @PostMapping("/logout")
    @ApiOperation(value = "注销退出登录")
    public Result logout(){
        return Result.success("退出成功！");
    }

//    @ApiOperation(value = "test")
//    @GetMapping("/test")
//    public String test(){
//        return "hello,Test";
//    }
}
